package com.cqut.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cqut.service.IMessageNotificationService;
import com.cqut.model.MessageNotification;
import com.cqut.util.SqlUtil;
import com.cqut.dao.MessageNotificationMapper;

@Service
public class MessageNotificationService implements IMessageNotificationService {
    @Resource(name="messageNotificationMapper")
    private MessageNotificationMapper messageNotificationMapper;

    @Override
    public boolean save(MessageNotification messageNotification) {
        return messageNotificationMapper.insert(messageNotification) > 0;
    }

    @Override
    public boolean update(MessageNotification messageNotification) {
        return messageNotificationMapper.updateByPrimaryKeySelective(messageNotification) >= 0;
    }

    @Override
    public boolean delete(String messageId) {
        return messageNotificationMapper.deleteByPrimaryKey(messageId) > 0;
    }

    @Override
    public boolean batchDelete(String[] primaryKeys) {
        return messageNotificationMapper.deleteByPrimaryKeys(primaryKeys) > 0;
    }

    @Override
    public MessageNotification findModel(String messageId) {
        return messageNotificationMapper.selectByPrimaryKey(messageId);
    }

    @Override
    public MessageNotification findModel(String messageId, String[] parameters) {
        return messageNotificationMapper.findModel(messageId, SqlUtil.formatParameters(parameters));
    }

    public Map<String, Object> findMap(String messageId) {
        String[][] parameters = {{"message_id", "messageId"}, {"notice_id", "noticeId"}, {"message_time", "messageTime"}, {"message_type", "messageType"}, {"message", "message"}};
        return this.findMap(messageId, parameters);
    }

    public Map<String, Object> findMap(String messageId, String[][] parameters) {
        return messageNotificationMapper.findMap(messageId, SqlUtil.formatParametersForAlias(parameters));
    }

    @Override
    public List<MessageNotification> loadModels() {
        return this.loadModels(null, null, null, null, -1, -1);
    }

    @Override
    public List<MessageNotification> loadModels(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return this.loadModels(null, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<MessageNotification> loadModels(String[] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return messageNotificationMapper.loadModels(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps() {
        String[][] parameters = {{"message_id", "messageId"}, {"notice_id", "noticeId"}, {"message_time", "messageTime"}, {"message_type", "messageType"}, {"message", "message"}};
        return this.loadMaps(parameters, null, null, null, null, -1, -1);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        String[][] parameters = {{"message_id", "messageId"}, {"notice_id", "noticeId"}, {"message_time", "messageTime"}, {"message_type", "messageType"}, {"message", "message"}};
        return this.loadMaps(parameters, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String[][] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return messageNotificationMapper.loadMaps(SqlUtil.formatParametersForAlias(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public long count() {
        return this.count(null, false);
    }

    @Override
    public long count(String condition, Object[] values) {
        return this.count(null, condition, values, false);
    }

    @Override
    public long count(String[] parameters, boolean isDistinct) {
        return this.count(parameters, null, null, isDistinct);
    }

    @Override
    public long count(String[] parameters, String condition, Object[] values, boolean isDistinct) {
        return messageNotificationMapper.count(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), isDistinct);
    }

}
